package com.situ.feemanagement.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.feemanagement.mapper.PatientMapper;
import com.situ.feemanagement.pojo.Patient;
import com.situ.feemanagement.pojo.query.PatientQuery;
import com.situ.feemanagement.service.IPatientService;
import com.situ.feemanagement.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PatientServiceImpl implements IPatientService {

    @Autowired
    private PatientMapper patientMapper;

    @Override
    public PageResult<Patient> selectByPage(PatientQuery patientQuery) {
        PageHelper.startPage(patientQuery.getPage(), patientQuery.getLimit());
        List<Patient> list = patientMapper.selectByPage(patientQuery);
        PageInfo<Patient> pageInfo = new PageInfo<>(list);
        int totalCount = (int) pageInfo.getTotal();
        return new PageResult<>(0, "", totalCount, list);
    }

    @Override
    public void deleteById(int id) {
        patientMapper.deleteById(id);
    }

    @Override
    public void deleteAll(String[] ids) {
        for (String id : ids) {
            patientMapper.deleteById(Integer.parseInt(id));
        }
    }

    @Override
    public void add(Patient patient) {
        patientMapper.add(patient);
    }

    @Override
    public Patient selectById(int id) {
        return patientMapper.selectById(id);
    }

    @Override
    public void update(Patient patient) {
        patientMapper.update(patient);
    }

    @Override
    public List<Patient> selectAll() {
        return patientMapper.selectAll();
    }
}
